package com.jsb.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.jsb.mapper.CategoryMapper;
import com.jsb.mapper.ExtraCategoryMapper;
import com.jsb.model.Category;
import com.jsb.model.CategoryExample;

@Service
public class CategoryService{
	
	@Resource
	private CategoryMapper categoryMapper;
	
	@Resource
	private ExtraCategoryMapper extraCategoryMapper;
	
	
	public void addCategory(Category category) {
		categoryMapper.insertSelective(category);
	}
	
	public void delCategoryByUuid(String uuid) {
		categoryMapper.deleteByPrimaryKey(uuid);
	}
	
	public void updateCategory(Category category) {
		categoryMapper.updateByPrimaryKeySelective(category);
	}
	
	public void updateCategoryByExample(Category category,CategoryExample categoryExample){
	    categoryMapper.updateByExampleSelective(category,categoryExample);
	}
	
	public Category getCategoryByUuid(String uuid) {
		return categoryMapper.selectByPrimaryKey(uuid);
	}
	
	public List<Category> getPageCategory(CategoryExample categoryExample) {
		return categoryMapper.selectPage(categoryExample);
	}
	
	public int countCategory(CategoryExample categoryExample) {
		return categoryMapper.countByExample(categoryExample);
	}
	
	public List<Category> selectByExample(CategoryExample example){
	    return categoryMapper.selectByExample(example);
	}
	
	public List<Category> getCategoryList(String id){
		return extraCategoryMapper.getCategoryList(id);
	}
	
	public List<Category> getSameLevel(String id){
		Category selectByPrimaryKey = categoryMapper.selectByPrimaryKey(id);
		String pid = selectByPrimaryKey.getPid();
		return getCategoryList(pid);
	}
}
